Skip to main content

Window.history

  • history.back() : 与在浏览器点击后退按钮相同
  • history.forward() :与在浏览器中点击向前按钮相同
  • history.go()
    • history.go(-1) :后退一个页面,等同于调用了 back()
    • history.go(1):前进一个页面,等同于调用了 forward()
  • history.pushState(state, title, url):往 history 栈栈顶压入一条新的历史记录,并改变当前指针至栈顶。
history.pushState({ page: 1 }, 'title 1', '?page=1')
  • history.replaceState(state, title, url):往 history 栈栈顶压入一条新的历史记录,并改变当前指针至栈顶。
history.replaceState({ page: 3 }, 'title 3', '?page=3')

参考文章:https://webcache.googleusercontent.com/search?q=cache:UjN4CehRWU8J:https://juejin.cn/post/6844904202213277704+&cd=3&hl=zh-CN&ct=clnk&gl=nl